app.post("/listByPage",function (req,res) {
    let whereCase="1=1 ";
    if(req.params.name){
        whereCase=whereCase+` and name like '%${req.params.name}%'`
    }
    const sql1=` 
    select * from resource  where ${whereCase}  limit  ${(req.params.startPage-1)*req.params.limit},${req.params.limit}`
   const sql2= `
        select count(1) c from resource  where ${whereCase};
    `;
    M.Db().doSql(sql1).then((d) => {
        let rows = d.rows;
        M.Db().doSql(sql2).then((d) => {
            let total = d.rows[0].c; 
            rows= Array.from(rows);
            res.send({rows ,total});
        });
    })
});


app.post("/add",function (req,res) {
    let values=req.params;
    delete values.id;
    let sql = M.Db().getInsertObjSql("resource",values) + ";";
    M.Db().doSql(sql).then(d=>{
        res.send("ok");
    })
});

app.post("/update",function (req,res) {
    let values=req.params;
    let sql = M.Db().getUpdateObjSql("resource",values) + ";";
    M.Db().doSql(sql).then(d=>{
        res.send("ok");
    })
});


app.get("/delete",function (req,res) {
    let sql=`delete from resource where id=${req.params.id};`
    M.Db().doSql(sql).then(d=>{
        res.send("ok");
    })
});


app.get("/deleteAll",function (req,res) {
    let sql=`delete from resource;`
    M.Db().doSql(sql).then(d=>{
        res.send("ok");
    })
});








